home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Think Class Libraries / CMovieController 1.0 / CShellApp.cp < prev    next >
Encoding:
Text File  |  1994-11-30  |  7.5 KB  |  283 lines  |  [TEXT/KAHL]

  1. /*****
  2.  * CShellApp.c
  3.  *
  4.  *    Application methods for a typical application.
  5.  *
  6.  *  Copyright © 1990 Symantec Corporation.  All rights reserved.
  7.  *
  8.  *****/
  9.  
  10. #include "CShellApp.h"
  11. #include "CShellDialog.h"
  12. #include "CDLOGDirector.h"
  13.  
  14.     // to suppress class stripping only
  15. #include "CButton.h"
  16. #include "CRadioControl.h"
  17. #include "CRadioGroupPane.h"
  18. #include "CStdPopupPane.h"
  19. #include "CCheckBox.h"
  20. #include "CIconPane.h"
  21. #include "CIntegerText.h"
  22. #include "CMovieController.h"
  23.  
  24. extern    OSType                    gSignature;
  25. extern     CBartender                *gBartender;        /* Manages all menus                */
  26.  
  27. #define        cmdNewControllerFromRes        1025
  28. #define        cmdNewControllerFromFile    1026
  29.  
  30. #define        kExtraMasters        4
  31. #define        kRainyDayFund        20480
  32. #define        kCriticalBalance    20480
  33. #define        kToolboxBalance        20480
  34.  
  35. #define        kShellDLOGID        1024
  36.  
  37. /***
  38.  * IShellApp
  39.  *
  40.  *    Initialize the application. Your initialization method should
  41.  *    at least call the inherited method. If your application class
  42.  *    defines its own instance variables or global variables, this
  43.  *    is a good place to initialize them.
  44.  *
  45.  ***/
  46.  
  47. void CShellApp::IShellApp(void)
  48.  
  49. {
  50.     CApplication::IApplication( kExtraMasters, kRainyDayFund, 
  51.                         kCriticalBalance, kToolboxBalance);
  52.     
  53.  
  54. /*  The parameters to IApplication are the number of times to call  
  55.     MoreMasters, the total number of bytes of heap space to reserve for                       
  56.     monitoring low memory situations, and the portion of the memory
  57.     reserve to set aside for critical operations and toolbox calls.
  58.     
  59.     Four (4) is a reasonable number of MoreMasters calls,                           
  60.     but you should determine a good number for your application                     
  61.     by observing the heap using Lightsbug,                                              
  62.     TMON, or Macsbug. Set this parameter to zero, give your                         
  63.     program a rigorous work-out, then look at the heap and count                        
  64.     how many master pointer blocks have been allocated. Master                      
  65.     pointer blocks are nonrelocatable and have a size of $100                           
  66.     (hex). You should call MoreMasters at least this many                               
  67.     times -- add a few extra just to be safe. The purpose of all                        
  68.     this preflighting is to prevent heap fragmentation. You                             
  69.     don't want the Memory Manager to call MoreMasters and                           
  70.     create a nonrelocatable block in the middle of your heap. By                        
  71.     calling MoreMasters at the very beginning of the program,                           
  72.     you ensure that these blocks are allocated in a group at the                        
  73.     bottom of the heap. 
  74.                                                                         
  75.     The memory reserve is a safeguard for handling low memory                   
  76.     conditions and is used by the GrowMemory method in                              
  77.     CApplication (check there for more comments). In general,                           
  78.     your program should never request a memory block greater                        
  79.     than this reserve size without explicitly checking in                               
  80.     advance whether there is enough free memory to satisfy the                      
  81.     the request.
  82.                                                                                     
  83.  */
  84.  
  85. }
  86.  
  87.  
  88.  
  89. /***
  90.  * SetUpFileParameters
  91.  *
  92.  *    In this routine, you specify the kinds of files your
  93.  *    application opens.
  94.  *
  95.  *
  96.  ***/
  97.  
  98. void CShellApp::SetUpFileParameters(void)
  99.  
  100. {
  101.     inherited::SetUpFileParameters();    /* Be sure to call the default method */
  102.  
  103.         /**
  104.          **    sfNumTypes is the number of file types
  105.          **    your application knows about.
  106.          **    sfFileTypes[] is an array of file types.
  107.          **    You can define up to 4 file types in
  108.          **    sfFileTypes[].
  109.          **
  110.          **/
  111.  
  112.     sfNumTypes = 1;
  113.     sfFileTypes[0] = 'TEXT';
  114.  
  115.         /**
  116.          **    Although it's not an instance variable,
  117.          **    this method is a good place to set the
  118.          **    gSignature global variable. Set this global
  119.          **    to your application's signature. You'll use it
  120.          **    to create a file (see CFile::CreateNew()).
  121.          **
  122.          **/
  123.  
  124.     gSignature = '?\??\?';
  125. }
  126.  
  127. /***
  128.  * SetUpMenus 
  129.  *
  130.  * Set up menus which must be created at run time, such as a
  131.  * Font menu. You can eliminate this method if your application
  132.  * does not have any such menus.
  133.  *
  134. ***/
  135.  
  136.  void CShellApp::SetUpMenus()
  137.  {
  138.  
  139.   inherited::SetUpMenus();  /*  Superclass takes care of adding     
  140.                                 menus specified in a MBAR id = 1    
  141.                                 resource    
  142.                             */                          
  143.  
  144.         /* Add your code for creating run-time menus here */    
  145.  }
  146.  
  147.  
  148.  
  149. /***
  150.  * DoCommand
  151.  *
  152.  *    Your application will probably handle its own commands.
  153.  *    Remember, the command numbers from 1-1023 are reserved.
  154.  *  The file Commands.h contains all the predefined TCL
  155.  *  commands.
  156.  *
  157.  *    Be sure to call the default method, so you can get
  158.  *    the default behvior for standard commands.
  159.  *
  160.  ***/
  161. void CShellApp::DoCommand(long theCommand)
  162.  
  163. {
  164.     CDirector     *director;
  165.  
  166.     switch (theCommand) {
  167.     
  168.         /* Your commands go here */
  169.         case cmdNewControllerFromRes:
  170.             director = DoShellDialogClass(FALSE, 1025);
  171.             break;
  172.             
  173.         case cmdNewControllerFromFile:
  174.             director = DoShellDialogClass(FALSE, 1024);
  175.             break;
  176.             
  177.         case cmdNew:
  178.             break;    
  179.         default:    inherited::DoCommand(theCommand);
  180.                     break;
  181.     }
  182. }
  183.  
  184.  
  185. /***
  186.  *
  187.  * UpdateMenus 
  188.  *
  189.  *   Perform menu management tasks
  190.  *
  191. ***/
  192.  
  193.  void CShellApp::UpdateMenus()
  194.  {
  195.   inherited::UpdateMenus();     /* Enable standard commands */      
  196.  
  197.     /* Enable the commands handled by your Application class */ 
  198.     gBartender->EnableCmd(cmdNewControllerFromRes);
  199.     gBartender->EnableCmd(cmdNewControllerFromFile);
  200.  }
  201.  
  202.  
  203. /***
  204.  * Exit
  205.  *
  206.  *    Chances are you won't need this method.
  207.  *    This is the last chance your application gets to clean up
  208.  *  things like temporary files before terminating.
  209.  *
  210.  ***/
  211.  
  212. void CShellApp::Exit()
  213.  
  214. {
  215.     /* your exit handler here */
  216. }
  217.  
  218.  
  219. /******************************************************************************
  220.  ForceClassReferences
  221.  
  222.      This method creates dummy references to classes that we don't want
  223.      stripped out by the linker when the application is built. This could
  224.      happen if the class is only created via new_by_name and is never directly
  225.      referenced. CApplication automatically calls this method.
  226.      
  227. ******************************************************************************/
  228.  
  229.  
  230. void    CShellApp::ForceClassReferences( void)
  231. {
  232.     Boolean alwaysFalse = FALSE;
  233.     CObject *dummy = NULL;
  234.     
  235.     if (alwaysFalse == TRUE)
  236.     {
  237.         member( dummy, CButton);
  238.         member( dummy, CCheckBox);
  239.         member( dummy, CRadioControl);
  240.         member( dummy, CRadioGroupPane);
  241.         member( dummy, CIconPane);
  242.         member( dummy, CIntegerText);
  243.         member( dummy, CStdPopupPane);
  244.         member( dummy, CMovieController);
  245.     }
  246. }
  247.  
  248.  
  249. /******************************************************************************
  250.  DoShellDialogClass
  251.  
  252.      Like DoShellDialog but creates the object from a specific CShellDialog lass.
  253. ******************************************************************************/
  254.  
  255. CDirector *CShellApp::DoShellDialogClass(Boolean modal, short ShellDialogID)
  256. {
  257.     CShellDialog        *dialog = NULL;
  258.     long            cmd;
  259.     
  260.     TRY
  261.     {
  262.         dialog = new CShellDialog;    
  263.         dialog->IShellDialog(ShellDialogID);
  264.         dialog->BeginDialog();
  265.  
  266.         if (modal)
  267.         {
  268.             cmd = dialog->DoModalDialog( cmdOK);    
  269.             ForgetObject( dialog);
  270.         }
  271.     }
  272.     CATCH
  273.     {
  274.         ForgetObject( dialog);
  275.     }
  276.     ENDTRY;
  277.     
  278.     return dialog; // not null if dialog is non-modal
  279.  
  280. }
  281.  
  282.  
  283.